/**
 * Created on 19/04/2008
 * 
 */
package com.apbetioli.mapr.project.dao;

import com.apbetioli.mapr.project.entity.Project;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityTransaction;

/**
 *
 * @author Alexandre Parra Betioli
 */
public final class ProjectsDao extends ProjectsDaoNoTransaction {
    
    @Override
    public Project save( final Project project ) {
        EntityTransaction et = super.getTransaction();
        Project old = null;
        
        try {
            et.begin();
            old = super.save(project);
            et.commit();
        }
        catch( RuntimeException e ) {
            Logger.getLogger(ProjectsDao.class.getName()).log(Level.SEVERE, null, e);
            if( et.isActive() )
                et.rollback();
            throw e;
        }
        
        return old;
    }
    
    @Override
    public Project delete( final String key ) {
        EntityTransaction et = super.getTransaction();
        Project old = null;
        try {
            et.begin();
            old = super.delete(key);
            et.commit();
        }
        catch ( RuntimeException e ) {
            Logger.getLogger(ProjectsDao.class.getName()).log(Level.SEVERE, null, e);
            if( et.isActive() )
                et.rollback();
            throw e;
        }
     
        return old;
    }
}
